<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>事件阻止冒泡</title>

    <style>
        #outer {
            width: 400px;
            height: 400px;
            background-color: deeppink;
        }
        
        #middle {
            width: 300px;
            height: 300px;
            background-color: deepskyblue;
        }
        
        #inner {
            width: 200px;
            height: 200px;
            background-color: darkgreen;
            text-align: center;
            color: white;
        }
        div{
            margin: auto;
            padding-top: 50px;
        }
    </style>
</head>
<body>
    <div id="outer">
        <div id="middle">
            <div id="inner">
                最小的框
            </div>
        </div>
    </div>
    
    <script type="text/javascript">
        function ShowMsg(msg){
            alert("这是一个操作" + msg);
        }
        var a = document.getElementById("inner");
        a.onclick = function(){
            ShowMsg("小框");
            //阻止冒泡
            window.event.cancelBubble= true;
        }

        var b = document.getElementById("middle");
        b.onclick = function(){
            ShowMsg("中框");
            window.event.cancelBubble= true;
        }

        var c = document.getElementById("outer");
        c.onclick = function(){
            ShowMsg("大框");
            window.event.cancelBubble= true;
        }
    </script>
</body>
</html>